package com.aqie.easy.hash;

/**
 * 463. 岛屿的周长
 *  todo
 */
public class IslandPerimeter {
    public int islandPerimeter(int[][] grid) {
        int R = grid.length;
        int C = grid[0].length;

        int ans = 0;
        for (int i = 0; i < R; i++){
            for (int j = 0; j < C; j++){
                if (grid[i][j] == 1){
                    if (i == 0 || grid[i - 1][j] == 0) ans++;
                    if (j == 0 || grid[i][j - 1] == 0) ans++;
                }
            }
        }
        ans *= 2;
        return ans;
    }
}
